package lab3_2;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JList;

/**
 * <p>Title: Main program for Lab #3</p>
 * <p>Description: CSIS 343 Lab on 
 *		Swing JList class for GUI
 *		Model-View design pattern
 *      Java Collections
 *      Generics
 * </p>
 * 
 * @author tony
 * @date  10.01.2011
 * @email anthony.varghese@uwrf.edu
 * @version 3
 *
 */
public class SimpleJList extends JFrame {
	/**
	 * Data members
	 */
	private static final long serialVersionUID = 3L;
	private static final String INPUT_FILE = "src/lab3_2/stars";

	private JList listView;
	
	public SimpleJList(){
		setBounds( 100, 100, 400, 300 );
		setVisible( true );
		setDefaultCloseOperation( EXIT_ON_CLOSE );
	}
	
	
	/**
	 * main
	 *    Reads contents of a file into a LinkedList Collections object
	 *      and displays it in a Swing JList object in a window. 
	 * @param args
	 */
	public static void main(String[] args) {
		java.util.List<Star> list = new java.util.LinkedList<Star>();

		try {
			Scanner in = new Scanner( new FileReader( INPUT_FILE ) );
			// read in and ignore the first line of the file
			in.nextLine();
			while (in.hasNext()){
				String name = in.next();
				double sunM = in.nextDouble();
				int    jupM = in.nextInt();
				list.add( new Star( name, jupM, sunM) );
			}
			in.close();
			
		} catch (FileNotFoundException e) {
			System.err.println("Not able to open file: " + INPUT_FILE );
			System.exit( -1 );
		}
		
		/*
		 * Check if the file was read in properly.
		 */
		for (Star s : list )
			System.out.println(s);
		
		/*
		 * Now open the window and display the list.
		 */
		new SimpleJList();
	}

}